/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.designtime.generator.api;


import com.inspur.edp.bff.designtime.generator.VmGeneratorContext;
import com.inspur.edp.bff.designtime.generator.api.actioninterface.ActionInterfaceGenerator;
import com.inspur.edp.bff.designtime.generator.api.actioninterface.SingleServiceGenerator;
import com.inspur.edp.bff.designtime.generator.api.actioninterface.resourceinfo.BffModelInfoGenerator;
import com.inspur.edp.bff.designtime.generator.api.entityinterface.VoEntityAllInterfaceGenerator;
import com.inspur.edp.bff.designtime.generator.api.entityinterface.VoEntityInterfaceGenerator;
import com.inspur.edp.bff.designtime.generator.api.entityinterface.VoEntitySingleInterfaceGenerator;
import com.inspur.edp.bff.designtime.generator.api.service.ServiceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.commonModel.CommonModelApiGenerator;
import com.inspur.edp.cef.generator.apiGenerator.commonModel.CommonModelApiGeneratorContext;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrAllInterface.MgrAllInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.MgrInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.MgrSingleInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.dataType.mgrInterface.resourceInfo.ModelInfoBaseGenerator;
import com.inspur.edp.cef.generator.apiGenerator.entity.allInterface.EntityAllInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.entity.separateInterface.EntityInterfaceGenerator;
import com.inspur.edp.cef.generator.apiGenerator.entity.separateInterface.EntitySingleInterfaceGenerator;

public class VmApiGenerator extends CommonModelApiGenerator {

  private VmGeneratorContext vmGenCtx;

  public VmApiGenerator(VmGeneratorContext vmGenCtx) {
    super(vmGenCtx, vmGenCtx.getVm(), vmGenCtx.getParentVo());
    this.vmGenCtx = vmGenCtx;
  }

  @Override
  public VmApiGenContext getContext() {
    return (VmApiGenContext) super.getContext();
  }

  @Override
  protected CommonModelApiGeneratorContext createCMApiGenCtx() {
    VmApiGenContext api = new VmApiGenContext(vmGenCtx, vmGenCtx.getVm(), vmGenCtx.getParentVo());
    vmGenCtx.setApiGenContext(api);
    return api;
  }

  protected boolean getIsSingleInterface() {
    return vmGenCtx.getVm().isSimplifyGen();
  }

  @Override
  protected EntityInterfaceGenerator getEntityInterfaceGenerator() {
    return new VoEntityInterfaceGenerator(getContext(), vmGenCtx.getVm().getMainObject());
  }

  @Override
  protected EntityAllInterfaceGenerator getEntityAllInterfaceGenerator() {
    return new VoEntityAllInterfaceGenerator(getContext(), vmGenCtx.getVm().getMainObject());
  }

  @Override
  protected EntitySingleInterfaceGenerator getEntitySingleInterfaceGenerator() {
    return new VoEntitySingleInterfaceGenerator(getContext(), vmGenCtx.getVm().getMainObject());
  }

  @Override
  protected String getPackageName() {
    return vmGenCtx.getVm().getApiNamespace().getDefaultNamespace();
  }

  @Override
  protected MgrInterfaceGenerator getMgrInterfaceGenerator() {
    return new ActionInterfaceGenerator(getContext());
  }

  @Override
  protected MgrAllInterfaceGenerator getMgrAllInterfaceGenerator() {
    return new ServiceGenerator(getContext());
  }

  @Override
  protected MgrSingleInterfaceGenerator getSingleMgrInterfaceGenerator() {
    return new SingleServiceGenerator(getContext());
  }

  //  @Override
//  protected MgrInfoBaseGenerator createMgrInfoGenerator() {
//    return new VoMgrInfoGenerator((VoMgrInterfaceGenCtx) getContext(),
//        apiGenCtx.getVmGenContext().getVm());
//  }

  @Override
  protected ModelInfoBaseGenerator createModelInfoGenerator() {
    return new BffModelInfoGenerator(getContext(), getContext().getVmGenContext().getVm());
  }

//  /**
//   * 是否生成BEManager Api
//   *
//   * @return 生成/不生成
//   */
//  @Override
//  protected boolean getHasMgrInterface() {
//    return !getContext().getCommonModel().isSimplifyGen();
//  }


//  @Override
//  protected void beforeGenerate() {
//    super.beforeGenerate();
//    setRefProjectGen(vmGenCtx.getRefGenerator());
//  }
}
